package Application.service;

import Application.client.SearchClient;
import Application.entity.Customer;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerService {
    @Autowired
    private SearchClient searchClient;
    @CacheResult
    @HystrixCommand(commandKey ="searchById" )
    public Customer searchById(@CacheKey Integer id) {
        return searchClient.searchById(id);
    }
    @CacheRemove(commandKey ="searchById" )
    @HystrixCommand
    public void clearCache(@CacheKey Integer id){
        System.out.println("缓存清除");
    }
}
